package cn.jiyun.controller;

import cn.jiyun.pojo.User;
import cn.jiyun.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;


    @Value("${user.name}")
    private String name;

    @GetMapping("{id}")
    public User findById(@PathVariable Long id){
        System.out.println(name);
        return userService.findById(id);
    }

    @GetMapping("findPage")
    public Page<User> findPage(@RequestParam(required = true,defaultValue = "1")Integer pageIndex,String name){
        Page<User> page = userService.findPage(pageIndex,name);


        return page;
    }

    @GetMapping("del")
    public void del(Integer id){
        userService.del(id);
    }

    @PostMapping("add")
    public void add(@RequestBody User user){
        userService.add(user);
    }

    @GetMapping("findById")
    public User findById(Integer id){
        return userService.findId(id);
    }

    @PostMapping("edit")
    public void edit(@RequestBody User user){
        userService.edit(user);
    }
}
